package com.z8888q.zstopwatch.animation;

import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

public class AnimationController {

	private Animation showAction;
	private Animation hideAction;
	protected static long animationDuration = 1000;

	public AnimationController() {
		setTheAnimationType();
	}

	protected void setTheAnimationType() {
		showAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
		hideAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				0.0f, Animation.RELATIVE_TO_SELF, 1.0f);
		// TODO set rightness time duration
		hideAction.setInterpolator(new AccelerateInterpolator((float) 4.0));
		showAction.setInterpolator(new AccelerateDecelerateInterpolator());
	}

	/**
	 * @preserve
	 */
	public void showAction(ViewGroup view) {
		if (view.getVisibility() != View.VISIBLE) {
			view.setVisibility(View.VISIBLE);
			try {
				showAction.setDuration(animationDuration);
			} catch (IllegalArgumentException e) {
			}

			view.startAnimation(showAction);
		}
	}

	/**
	 * @preserve
	 */
	public void hideAction(ViewGroup view) {
		if (view.getVisibility() == View.VISIBLE) {
			try {
				hideAction.setDuration(animationDuration);
			} catch (IllegalArgumentException e) {
			}
			view.startAnimation(hideAction);
			view.setVisibility(View.GONE);

		}
	}

}
